﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NapCardOnline.Models
{
    public partial class Contact
    {
        static NapCardOnlineEntities db = new NapCardOnlineEntities();

        /// <summary>
        /// Gets the contact by phone number.
        /// </summary>
        /// <param name="phoneNumber">The phone number.</param>
        /// <returns></returns>
        public static Contact GetContactByPhoneNumber(string phoneNumber)
        {
            return db.Contacts.FirstOrDefault(c => c.ContactNumber == phoneNumber.Trim());
        }

        /// <summary>
        /// Gets the contact by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static Contact GetContactById(int id)
        {
            return db.Contacts.FirstOrDefault(c => c.ContactID == id);
        }
        public static int Save(Contact objContact)
        {
            if (objContact.ContactID == 0)
            {
                //Create
                db.Contacts.AddObject(objContact);
            }
            return db.SaveChanges();
        }
        public static void Delete(Contact objContact)
        {
            db.Contacts.DeleteObject(objContact);
            db.SaveChanges();
        }
    }
}